
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TrainingsApp.Model;
using TrainingsApp.Helper;
using WisDragon.Framework.Data.DataAccess;

namespace TrainingsApp.DAL {
    public class TS_TeachMaterials_DAL {
        public static TS_TeachMaterials_Collecion TS_TeachMaterials_ListByPaging(int pageSize, int pageIndex) {
            TS_TeachMaterials_Collecion list = new TS_TeachMaterials_Collecion();
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_ListByPaging");
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                List<TS_TeachMaterials_Entity> pageList = cmd.ExecuteEntityList<TS_TeachMaterials_Entity>();
                list.TS_TeachMaterials_List = pageList;
                list.TotalCount = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return list;

        }

        public static List<TS_TeachMaterials_Entity> TS_TeachMaterials_ListForChildren(long schoolId, long classId) {

            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_ListForChildren");
                cmd.SetParameterValue("@SchoolId", schoolId);
                cmd.SetParameterValue("@ClassId", classId);
                List<TS_TeachMaterials_Entity> pageList = cmd.ExecuteEntityList<TS_TeachMaterials_Entity>();
                return pageList;

            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_TeachMaterials_Entity>(0);
        }


        public static List<TS_TeachMaterials_Entity> TS_TeachMaterials_ListForTeacher(long userId) {

            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_ListForChildren");
                cmd.SetParameterValue("@UserId", userId);

                List<TS_TeachMaterials_Entity> pageList = cmd.ExecuteEntityList<TS_TeachMaterials_Entity>();
                return pageList;

            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_TeachMaterials_Entity>(0);
        }

        public static List<TS_TeachMaterials_Entity> TS_TeachMaterials_ListAll() {

            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_ListAll");

                List<TS_TeachMaterials_Entity> pageList = cmd.ExecuteEntityList<TS_TeachMaterials_Entity>();
                return pageList;

            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_TeachMaterials_Entity>(0);
        }
        public static List<TS_TeachMaterials_Entity> TS_TeachMaterials_ListByCourse(int courseId) {

            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_ListByCourse");
                cmd.SetParameterValue("@CourseId", courseId);
                List<TS_TeachMaterials_Entity> pageList = cmd.ExecuteEntityList<TS_TeachMaterials_Entity>();
                return pageList;

            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<TS_TeachMaterials_Entity>(0);
        }


        public static TS_TeachMaterials_Entity TS_TeachMaterials_View(System.Int64 Idx) {
            TS_TeachMaterials_Entity c = default(TS_TeachMaterials_Entity);
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_View");
                cmd.SetParameterValue("@Idx", Idx);
                c = cmd.ExecuteEntity<TS_TeachMaterials_Entity>();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public static TS_TeachMaterials_Entity TS_TeachMaterials_Add(TS_TeachMaterials_Entity entity) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_Add");
                cmd.SetParameterValue("@CourseId", entity.CourseId);
                cmd.SetParameterValue("@Name", entity.Name);
                cmd.SetParameterValue("@Grade", entity.Grade);
                cmd.SetParameterValue("@Code", entity.Code);
                cmd.SetParameterValue("@Version", entity.Version);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return entity;
        }

        public static void TS_TeachMaterials_Update(TS_TeachMaterials_Entity entity) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_Update");
                cmd.SetParameterValue("@Idx", entity.Idx);
                cmd.SetParameterValue("@CourseId", entity.CourseId);
                cmd.SetParameterValue("@Grade", entity.Grade);
                cmd.SetParameterValue("@Name", entity.Name);
                cmd.SetParameterValue("@Code", entity.Code);
                cmd.SetParameterValue("@Version", entity.Version);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
        }

        public static void TS_TeachMaterials_Delete(System.Int64 Idx) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("TS_TeachMaterials_Delete");
                cmd.SetParameterValue("@Idx", Idx);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
        }
    }
}
